/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IHM;

import TouristManagement.Directeur.Directeur;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import java.util.Map;
import javax.swing.JOptionPane;

/**
 *
 * @author HaBL
 */
public class DirectionIHM extends javax.swing.JFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * Creates new form Direction
     */
    private  Directeur direct;
    
    public DirectionIHM() {
        initComponents(); 
        setTitle("Direction office de tourisme");
        direct = new Directeur();        
        init();
         
    }
    
    @SuppressWarnings("unchecked")
	private void init(){

        direct.initServer();
        Map<Short,String> mp;
        mp = direct.getListSite();
        Cb_NumSite.addItem("...");
        for (Short i:mp.keySet()){
            Cb_NumSite.addItem(mp.get(i));   
        }
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("rawtypes")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jP_Globale = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        Lbl_ValSeqFavor = new javax.swing.JLabel();
        Btn_Statistique = new javax.swing.JButton();
        Lbl_TauxChaqueSite = new javax.swing.JLabel();
        jP_Site = new javax.swing.JPanel();
        Cb_NumSite = new javax.swing.JComboBox();
        Btn_Aff = new javax.swing.JButton();
        Lb_TitreStatSite = new javax.swing.JLabel();
        Lbl_Affluence = new javax.swing.JLabel();
        Lbl_DureeMoyen = new javax.swing.JLabel();
        Lbl_DureeMax = new javax.swing.JLabel();
        Lbl_DureeMin = new javax.swing.JLabel();
        Lbl_NumSite = new javax.swing.JLabel();
        Lbl_NomSite = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(580, 700));

        jLabel1.setFont(new java.awt.Font("Aharoni", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 51, 51));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Statistiques globales");

        Lbl_ValSeqFavor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_ValSeqFavor.setForeground(new java.awt.Color(204, 0, 51));
        Lbl_ValSeqFavor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_ValSeqFavor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Séquence visite favoriste", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(51, 51, 51))); // NOI18N

        Btn_Statistique.setText("Get statistiques globales");
        Btn_Statistique.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_StatistiqueActionPerformed(evt);
            }
        });

        Lbl_TauxChaqueSite.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Taux de satisfaction moyen chaque site", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(51, 51, 51))); // NOI18N

        javax.swing.GroupLayout jP_GlobaleLayout = new javax.swing.GroupLayout(jP_Globale);
        jP_Globale.setLayout(jP_GlobaleLayout);
        jP_GlobaleLayout.setHorizontalGroup(
            jP_GlobaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jP_GlobaleLayout.createSequentialGroup()
                .addGroup(jP_GlobaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jP_GlobaleLayout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addGroup(jP_GlobaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(Btn_Statistique, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE))
                        .addGap(0, 87, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jP_GlobaleLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jP_GlobaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Lbl_TauxChaqueSite, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Lbl_ValSeqFavor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jP_GlobaleLayout.setVerticalGroup(
            jP_GlobaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jP_GlobaleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(Btn_Statistique, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Lbl_ValSeqFavor, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Lbl_TauxChaqueSite, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(167, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Statistiques Globales", jP_Globale);

        Btn_Aff.setText("Get statistiques du site");
        Btn_Aff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_AffActionPerformed(evt);
            }
        });

        Lb_TitreStatSite.setFont(new java.awt.Font("Aharoni", 1, 24)); // NOI18N
        Lb_TitreStatSite.setForeground(new java.awt.Color(51, 51, 51));
        Lb_TitreStatSite.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lb_TitreStatSite.setText("Statistiques du site");

        Lbl_Affluence.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_Affluence.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_Affluence.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_Affluence.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Affluence quotidienne", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMoyen.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMoyen.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMoyen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMoyen.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite moyenne", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMax.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMax.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMax.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMax.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite maximale", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_DureeMin.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        Lbl_DureeMin.setForeground(new java.awt.Color(102, 0, 0));
        Lbl_DureeMin.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Lbl_DureeMin.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Durée visite minimal", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        Lbl_NumSite.setText("Nom du site");

        javax.swing.GroupLayout jP_SiteLayout = new javax.swing.GroupLayout(jP_Site);
        jP_Site.setLayout(jP_SiteLayout);
        jP_SiteLayout.setHorizontalGroup(
            jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jP_SiteLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(Lb_TitreStatSite, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                .addGap(57, 57, 57))
            .addGroup(jP_SiteLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jP_SiteLayout.createSequentialGroup()
                        .addComponent(Lbl_NumSite)
                        .addGap(68, 68, 68)
                        .addComponent(Cb_NumSite, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Btn_Aff, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                        .addGap(40, 40, 40))
                    .addGroup(jP_SiteLayout.createSequentialGroup()
                        .addGroup(jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(Lbl_DureeMax, javax.swing.GroupLayout.PREFERRED_SIZE, 486, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(Lbl_NomSite, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(Lbl_DureeMoyen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE))
                            .addComponent(Lbl_DureeMin, javax.swing.GroupLayout.PREFERRED_SIZE, 486, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Lbl_Affluence, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        jP_SiteLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {Lbl_Affluence, Lbl_DureeMax, Lbl_DureeMin, Lbl_DureeMoyen});

        jP_SiteLayout.setVerticalGroup(
            jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jP_SiteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Lb_TitreStatSite)
                .addGap(18, 18, 18)
                .addGroup(jP_SiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cb_NumSite)
                    .addComponent(Btn_Aff, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(Lbl_NumSite))
                .addGap(18, 18, 18)
                .addComponent(Lbl_NomSite, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Lbl_DureeMoyen, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Lbl_DureeMax)
                .addGap(18, 18, 18)
                .addComponent(Lbl_DureeMin)
                .addGap(26, 26, 26)
                .addComponent(Lbl_Affluence)
                .addGap(234, 234, 234))
        );

        jP_SiteLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {Lbl_Affluence, Lbl_DureeMax, Lbl_DureeMin, Lbl_DureeMoyen});

        jTabbedPane1.addTab("Statistiques site", jP_Site);

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Aide");

        jMenuItem2.setText("About");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Btn_StatistiqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Btn_StatistiqueActionPerformed
       Lbl_ValSeqFavor.setText(direct.consultStatGlobalVisitSequence());
       Map<String,String> adviceSite = direct.consultStatGlobalAdviceAverageSite();
       String resultStr=null;
       for (String s:adviceSite.keySet())
           if (resultStr == null) 
               resultStr="<html>Site "+s+ " - "+ adviceSite.get(s)+"<br/>";
           else
                resultStr=resultStr+"Site "+s+ " - "+ adviceSite.get(s)+"<br/>";
       resultStr+="</html>";
       Lbl_TauxChaqueSite.setText(resultStr);
       
       
    }//GEN-LAST:event_Btn_StatistiqueActionPerformed

    private void Btn_AffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Btn_AffActionPerformed
        if (this.Cb_NumSite.getSelectedItem().toString().equals("...")) {
            JOptionPane.showMessageDialog(this," Veuillez choisir le site à consulter","Attention",JOptionPane.WARNING_MESSAGE);

        }
        else
        {
            Map<String,String> consulLocal = direct.consultStatLocal(((short)Cb_NumSite.getSelectedIndex()));
            Lbl_NomSite.setText("Site: "+ consulLocal.get("nameSite"));
            Lbl_DureeMoyen.setText(consulLocal.get("durationAverage")+" minutes");
            Lbl_DureeMax.setText(consulLocal.get("durationMax")+" minutes");
            Lbl_DureeMin.setText(consulLocal.get("durationMin")+" minutes");
            Lbl_Affluence.setText(consulLocal.get("affluenceQuotidienne"));
        }
    }//GEN-LAST:event_Btn_AffActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        WindowEvent winEvent= new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winEvent);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        new ZAboutIHM().setVisible(true);

    }//GEN-LAST:event_jMenuItem2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DirectionIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DirectionIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DirectionIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DirectionIHM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DirectionIHM().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Btn_Aff;
    private javax.swing.JButton Btn_Statistique;
    private javax.swing.JComboBox Cb_NumSite;
    private javax.swing.JLabel Lb_TitreStatSite;
    private javax.swing.JLabel Lbl_Affluence;
    private javax.swing.JLabel Lbl_DureeMax;
    private javax.swing.JLabel Lbl_DureeMin;
    private javax.swing.JLabel Lbl_DureeMoyen;
    private javax.swing.JLabel Lbl_NomSite;
    private javax.swing.JLabel Lbl_NumSite;
    private javax.swing.JLabel Lbl_TauxChaqueSite;
    private javax.swing.JLabel Lbl_ValSeqFavor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jP_Globale;
    private javax.swing.JPanel jP_Site;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
